<template>
  <div style="height: 100%">
    <callSummary
      :componentHeight="213"
      :propData="callData"
      :randomNum="randomNum"
      moduleType="autoCallTaskScreen"
      :showListen="showListen"
      :showDowload="showDowload"
      @changeCustomerRelation="changeCustomerRelation"
    ></callSummary>
  </div>
</template>

<script lang="ts">
import CallSummary from '@/components/commonSummary/index.vue'
import { Component, Vue } from 'vue-property-decorator'
import { CallCardModule } from '@/store/modules/cti/callCard'
import { checkPermission } from '@/utils/directive'
@Component({ name: 'CallSummaryByCallData', components: { CallSummary } })
export default class CallSummaryByCallData extends Vue {
  private $bus: any
  private $router: any
  private callData: any = {}
  private randomNum = 0
  private showDowload: boolean = false
  private showListen: boolean = false

  private mounted () {
    const status = this.$bus.$subscribed('initAutoCallTaskCall')
    if (status) {
      return false
    }
    /**
     * importType: 调用的模块|类型 required
     * timeStamp: 时间戳 required
     * phone: 通话号码 required
     * custId: 客户Id required
     * custName: 客户名称 required
     * customerList: 该号码对应的locateCust列表
     * callSheetId: 通话卡片id（通话记录的_id）
     * cdr: 该通话记录对应的数据
     * cdrName: 来电、外呼
     */
    this.$bus.$on(
      'initAutoCallTaskCall',
      (callObj: any) => {
        CallCardModule.CdrLocateCust({
          type: 1,
          phone: callObj.phone
        }).then((res) => {
          console.log(res, '测试测试========')
          if (res.success && res.data) {
            let cdrName: string = ''
            cdrName = 'cdr_call'
            const cdr: any = {}
            const customList = res.data || []
            if (customList.length === 1) {
              cdr.custName = customList[0].name || ''
              cdr.custId = customList[0].id || ''
            }
            cdr.taskName = callObj.taskName
            cdr.memo = callObj.memo || ''
            this.callData = {
              importType: 'AutoCallTaskScreen',
              timeStamp: new Date().getTime(),
              phone: callObj.phone,
              custId: cdr.custId,
              custName: cdr.custName,
              customerList: res.data || [],
              callSheetId: callObj.callSheetId,
              cdr,
              cdrName
            }
            console.log(this.callData, 'this.callData===========')
            this.randomNum = Math.random() + 1
          }
        })
      }
    )
  }

  private changeCustomerRelation (info) {
    CallCardModule.updateCardInfo(info)
  }

  private beforeMount () {
    if (checkPermission(null, { value: ['my_auto_call_task_list_voice_database_audition'] })) { //  试听，下载（自动外呼)
      this.showListen = true
      if (checkPermission(null, { value: ['my_auto_call_task_list_voice_database_download'] })) {
        this.showDowload = true
      }
    }
  }
}
</script>

<style lang="stylus" scoped></style>
